/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.mailbox.calendar.RecurId;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Map;
/*     */ import javax.mail.Address;
/*     */ import javax.mail.MessagingException;
/*     */ import javax.mail.internet.MimeMessage;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateCalendarItem
/*     */   extends CalendarRequest
/*     */ {
/*  47 */   private static final String[] TARGET_FOLDER_PATH = { "m", "l" };
/*  48 */   private static final String[] RESPONSE_ITEM_PATH = new String[0];
/*  49 */   protected String[] getProxiedIdPath(Element request) { return TARGET_FOLDER_PATH; }
/*  50 */   protected boolean checkMountpointProxy(Element request) { return true; }
/*  51 */   protected String[] getResponseItemPath() { return RESPONSE_ITEM_PATH; }
/*     */   
/*     */   protected class CreateCalendarItemInviteParser extends ParseMimeMessage.InviteParser {
/*     */     protected CreateCalendarItemInviteParser() {}
/*     */     
/*     */     public ParseMimeMessage.InviteParserResult parseInviteElement(ZimbraSoapContext lc, OperationContext octxt, Account account, Element inviteElem) throws ServiceException {
/*  57 */       return CalendarUtils.parseInviteForCreate(account, CreateCalendarItem.this.getItemType(), inviteElem, null, null, false, true);
/*     */     }
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException {
/*  62 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  63 */     Account acct = getRequestedAccount(zsc);
/*  64 */     Mailbox mbox = getRequestedMailbox(zsc);
/*  65 */     OperationContext octxt = getOperationContext(zsc, context);
/*     */     
/*     */ 
/*  68 */     Element msgElem = request.getElement("m");
/*     */     
/*  70 */     CreateCalendarItemInviteParser parser = new CreateCalendarItemInviteParser();
/*  71 */     CalendarRequest.CalSendData dat = handleMsgElement(zsc, octxt, msgElem, acct, mbox, parser);
/*     */     
/*  73 */     int defaultFolder = dat.mInvite.isTodo() ? 15 : 10;
/*  74 */     String defaultFolderStr = Integer.toString(defaultFolder);
/*  75 */     String folderIdStr = msgElem.getAttribute("l", defaultFolderStr);
/*  76 */     ItemId iidFolder = new ItemId(folderIdStr, zsc);
/*     */     
/*     */ 
/*  79 */     Folder folder = mbox.getFolderById(octxt, iidFolder.getId());
/*  80 */     if (folder.inTrash()) {
/*  81 */       throw ServiceException.INVALID_REQUEST("cannot create a calendar item under trash", null);
/*     */     }
/*     */     
/*  84 */     if (!dat.mInvite.hasRecurId()) {
/*  85 */       ZimbraLog.calendar.info("<CreateCalendarItem> folderId=%d, subject=\"%s\", UID=%s", new Object[] { Integer.valueOf(iidFolder.getId()), dat.mInvite.isPublic() ? dat.mInvite.getName() : "(private)", dat.mInvite.getUid() });
/*     */     }
/*     */     else
/*     */     {
/*  89 */       ZimbraLog.calendar.info("<CreateCalendarItem> folderId=%d, subject=\"%s\", UID=%s, recurId=%s", new Object[] { Integer.valueOf(iidFolder.getId()), dat.mInvite.isPublic() ? dat.mInvite.getName() : "(private)", dat.mInvite.getUid(), dat.mInvite.getRecurId().getDtZ() });
/*     */     }
/*     */     
/*     */ 
/*  93 */     Element response = getResponseElement(zsc);
/*     */     boolean hasRecipients;
/*     */     try
/*     */     {
/*  97 */       Address[] rcpts = dat.mMm.getAllRecipients();
/*  98 */       hasRecipients = (rcpts != null) && (rcpts.length > 0);
/*     */     } catch (MessagingException e) {
/* 100 */       throw ServiceException.FAILURE("Checking recipients of outgoing msg ", e);
/*     */     }
/*     */     
/* 103 */     if ((!dat.mInvite.isOrganizer()) && (hasRecipients)) {
/* 104 */       throw MailServiceException.MUST_BE_ORGANIZER("CreateCalendarItem");
/*     */     }
/* 106 */     if (!dat.mInvite.isOrganizer())
/*     */     {
/* 108 */       dat.mInvite.setNeverSent(false);
/* 109 */     } else if (!dat.mInvite.hasOtherAttendees())
/*     */     {
/* 111 */       dat.mInvite.setNeverSent(false);
/* 112 */     } else if (hasRecipients)
/*     */     {
/* 114 */       dat.mInvite.setNeverSent(false);
/*     */     }
/*     */     else {
/* 117 */       dat.mInvite.setNeverSent(true);
/*     */     }
/* 119 */     boolean forceSend = request.getAttributeBool("forcesend", true);
/* 120 */     CalendarRequest.MailSendQueue sendQueue = new CalendarRequest.MailSendQueue();
/*     */     try {
/* 122 */       sendCalendarMessage(zsc, octxt, iidFolder.getId(), acct, mbox, dat, response, true, forceSend, sendQueue);
/*     */     } finally {
/* 124 */       sendQueue.send();
/*     */     }
/* 126 */     boolean echo = request.getAttributeBool("echo", false);
/* 127 */     if ((echo) && (dat.mAddInvData != null)) {
/* 128 */       ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
/* 129 */       int maxSize = (int)request.getAttributeLong("max", 0L);
/* 130 */       boolean wantHTML = request.getAttributeBool("html", false);
/* 131 */       boolean neuter = request.getAttributeBool("neuter", true);
/* 132 */       echoAddedInvite(response, ifmt, octxt, mbox, dat.mAddInvData, maxSize, wantHTML, neuter);
/*     */     }
/* 134 */     return response;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/CreateCalendarItem.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */